package com.domor.xxx.system.domain;

import com.domor.xxx.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author domor
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private Long userId;

    private Long deptId;

    private Long parentId;

    @NotBlank(message = "登录账号不能为空")
    @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
    private String loginName;

    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    private String userName;

    private String userType;

    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    private String email;

    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    private String phone;

    private String sex;

    private String avatar;

    private String password;

    private String salt;

    private Integer status;

    private String loginIp;

    private Date loginDate;

    private SysDept dept;

    private String deptName;

    private List<SysRole> roles;

    private String roleName;

    public SysUser() {
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

}
